/*     */ package com.newcrm.webapi;
/*     */ 
/*     */ import com.newcrm.db.CompanyManager;
/*     */ import com.newcrm.db.UserManager;
/*     */ import com.newcrm.util.CaptchaUtil;
/*     */ import com.newcrm.util.MD5;
/*     */ import com.newcrm.util.ParameterUtil;
/*     */ import com.newcrm.util.Util;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import javax.servlet.RequestDispatcher;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServlet;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class Register extends HttpServlet
/*     */ {
/*     */   private static final long serialVersionUID = 5803877693166346236L;
/*  30 */   private static Logger logger = Logger.getLogger(Register.class.getName());
/*     */ 
/*     */   public void doGet(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/*  54 */     String url = request.getRequestURI();
/*  55 */     String[] param = ParameterUtil.getParameters(url, "/register");
/*  56 */     if ((param == null) || (param.length == 0)) {
/*  57 */       request.getRequestDispatcher("/register.jsp").forward(request, 
/*  58 */         response);
/*  59 */       return;
/*     */     }
/*  61 */     if ((param.length == 1) && (param[0].equals("result"))) {
/*  62 */       request.getRequestDispatcher("/register_finish.jsp").forward(
/*  63 */         request, response);
/*  64 */       return;
/*     */     }
/*     */ 
/*  68 */     if ((param.length == 1) && (param[0].equals("new"))) {
/*  69 */       String companyName = Util.getURLParameter(request
/*  70 */         .getParameter("companyName"));
/*  71 */       String category = Util.getURLParameter(request
/*  72 */         .getParameter("category"));
/*  73 */       String qq = Util.getURLParameter(request.getParameter("qq"));
/*  74 */       String mobile = 
/*  75 */         Util.getURLParameter(request.getParameter("mobile"));
/*  76 */       String code = Util.getURLParameter(request.getParameter("code"));
/*     */ 
/*  78 */       String userId = 
/*  79 */         Util.getURLParameter(request.getParameter("userId"));
/*  80 */       String userName = Util.getURLParameter(request
/*  81 */         .getParameter("userName"));
/*  82 */       String password = Util.getURLParameter(request
/*  83 */         .getParameter("password"));
/*  84 */       String comfirmPassword = Util.getURLParameter(request
/*  85 */         .getParameter("password2"));
/*  86 */       String email = Util.getURLParameter(request.getParameter("email"));
/*     */ 
/*  88 */       response.setContentType("text/html;charset=utf-8");
/*  89 */       PrintWriter out = response.getWriter();
/*     */ 
/*  91 */       JSONObject jsonObject = new JSONObject();
/*     */ 
/*  93 */       if (CaptchaUtil.checkCode(request, code)) {
/*  94 */         jsonObject.put("error", "1");
/*  95 */         jsonObject.put("errorMsg", "验证码输入错误");
/*  96 */         out.println(jsonObject);
/*  97 */         out.flush();
/*  98 */         out.close();
/*  99 */         return;
/*     */       }
/*     */ 
/* 102 */       if ((userId == null) || (userId.trim().length() == 0)) {
/* 103 */         jsonObject.put("error", "1");
/* 104 */         jsonObject.put("errorMsg", "请输入注册的用户名");
/* 105 */         out.println(jsonObject);
/* 106 */         out.flush();
/* 107 */         out.close();
/* 108 */         return;
/*     */       }
/*     */ 
/* 111 */       if ((password == null) || (password.trim().length() == 0)) {
/* 112 */         jsonObject.put("error", "1");
/* 113 */         jsonObject.put("errorMsg", "请输入登录的密码");
/* 114 */         out.println(jsonObject);
/* 115 */         out.flush();
/* 116 */         out.close();
/* 117 */         return;
/*     */       }
/*     */ 
/* 120 */       if (!password.equals(comfirmPassword)) {
/* 121 */         jsonObject.put("error", "1");
/* 122 */         jsonObject.put("errorMsg", "输入的密码和确认密码不一致");
/* 123 */         out.println(jsonObject);
/* 124 */         out.flush();
/* 125 */         out.close();
/* 126 */         return;
/*     */       }
/*     */ 
/* 129 */       CompanyManager companyManager = new CompanyManager();
/* 130 */       int companyId = 0;
/*     */       try
/*     */       {
/* 133 */         companyId = companyManager.add(companyName, 1, 2, category);
/*     */       } catch (Exception e) {
/* 135 */         logger.warn("add company info failed", e);
/*     */       }
/*     */ 
/* 138 */       if (companyId <= 0) {
/* 139 */         jsonObject.put("error", "1");
/* 140 */         jsonObject.put("errorMsg", "注册过程中，出现错误，请稍候再试");
/* 141 */         out.println(jsonObject);
/* 142 */         out.flush();
/* 143 */         out.close();
/* 144 */         return;
/*     */       }
/*     */ 
/* 147 */       UserManager userManager = new UserManager();
/*     */       try {
/* 149 */         userManager.addAdmin(userId, userName, email, qq, mobile, "", 
/* 150 */           MD5.getMD5(password), companyId);
/*     */       } catch (Exception e) {
/* 152 */         jsonObject.put("error", "1");
/* 153 */         jsonObject.put("errorMsg", "注册过程中，出现错误，请稍候再试");
/* 154 */         out.println(jsonObject);
/* 155 */         out.flush();
/* 156 */         out.close();
/* 157 */         return;
/*     */       }
/*     */ 
/* 160 */       jsonObject.put("error", "0");
/* 161 */       out.println(jsonObject);
/* 162 */       out.flush();
/* 163 */       out.close();
/* 164 */       return;
/*     */     }
/*     */   }
/*     */ 
/*     */   public void doPost(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/* 182 */     doGet(request, response);
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.Register
 * JD-Core Version:    0.6.1
 */